package Zijieliu;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Scanner;

public class Te04zuoye {
    //1. 请编写一个方法，实现指定文件的拷贝
    static Scanner sc = new Scanner(System.in);
    public static void StreamCopy() throws Exception{
        System.out.println("输入拷贝文件地址");
        String oldPath=sc.next();
        System.out.println("输入拷贝到文件地址");
        String path=sc.next();

        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            fis=new FileInputStream(oldPath);  //输入流
            fos=new FileOutputStream(path);    //输出流

            byte[] b = new byte[1024];    //字节
            int liu = fis.read(b);
            while (liu!=-1){
                fos.write(b,0,liu);
                liu=fis.read(b);
            }
            System.out.println("拷贝成功");
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            fis.close();
            fos.close();
        }
    }

    public static void main(String[]args){
    }
}
